package com.xunk.gateway.config;

import com.xunk.gateway.handler.AuthCodeHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.MediaType;
import org.springframework.web.reactive.function.server.RequestPredicates;
import org.springframework.web.reactive.function.server.RouterFunction;
import org.springframework.web.reactive.function.server.RouterFunctions;
import com.xunk.gateway.handler.ValidateCodeHandler;
import org.springframework.web.reactive.function.server.ServerResponse;

/**
 * 路由配置信息
 *
 * @author ruoyi
 */
@Configuration
public class RouterFunctionConfiguration {
    @Autowired
    private ValidateCodeHandler validateCodeHandler;

    @Autowired
    private AuthCodeHandler authCodeHandler;

    @SuppressWarnings("rawtypes")
    @Bean
    public RouterFunction<ServerResponse> routerFunction() {
        return RouterFunctions.route(
                RequestPredicates.GET("/code").and(RequestPredicates.accept(MediaType.TEXT_PLAIN)), validateCodeHandler)
                .andRoute(RequestPredicates.GET("/smscode").and(RequestPredicates.accept(MediaType.TEXT_PLAIN)), authCodeHandler);
    }
}
